package com.cdhkppm.service.impl;

import com.cdhkppm.service.IssueHelperService;
import com.hustcad.plm.basic.log.LogEventEnum;
import com.hustcad.plm.pdm.common.util.CommonUtil;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class IssueHelperServiceImpl implements IssueHelperService {
    @Resource
    private DyLogHelper dyLogHelper;
    /**
     * 集成成功失败记录审计日志
     * @param successMessage 成功信息
     * @param errorMessage 失败信息
     * @param eventName 事件名称
     */

    public void recordAuditLog(String successMessage, String errorMessage, LogEventEnum eventName, String requestBody) {
        if (StringUtils.isNotBlank(successMessage) || StringUtils.isNotBlank(errorMessage)) {
            String fullMessage = "\t\n成功信息：" + successMessage +
                    "\t\n失败信息：" + errorMessage +
                    "\t\n报文信息：" + requestBody;
            dyLogHelper.insertIntoLog(eventName.getLabel(), fullMessage, CommonUtil.getUserName(), eventName);
        }
    }
}
